package com.pets.controller;


import com.pets.dao.ApplyMapper;
import com.pets.qo.AuditApplyQO;
import com.pets.service.AdminUsersService;
import com.pets.service.ApplyService;
import com.pets.util.Result;
import com.pets.vo.UserApplyVO;
import com.pets.vo.UserListVO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.annotation.Resource;
import java.util.List;

/**
 * 后台管理系统操作用户
 */
@Controller
@RequestMapping(value = "/adminUser")
public class AdminUsersController {

    @Resource
    private AdminUsersService adminUsersService;

    @Resource
    private ApplyService applyService;


    @RequestMapping(value = "/getUserlist")
    public ModelAndView getUserlist(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/admin/member-list");
        List<UserListVO> usersList = adminUsersService.getUserlist();
        modelAndView.addObject("list",usersList);
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping(value ="/editUserStatus" ,method = RequestMethod.POST)
    public Result editUserStatus(int uId , int status){
        return adminUsersService.editUserStatus(uId,status);
    }

    @RequestMapping(value = "/toAuditApply")
    public ModelAndView toAuditApply(int uId){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setViewName("/admin/member-update");
        UserApplyVO userApplyVO = applyService.getUserApplyingByuId(uId);
        modelAndView.addObject("userApply",userApplyVO);
        return modelAndView;
    }

    @ResponseBody
    @RequestMapping(value = "/auditApply")
    public Result auditApply(AuditApplyQO auditApplyQO) {
        return adminUsersService.auditApply(auditApplyQO);
    }
}
